<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\virtual\controller;

class CallBack extends \app\ApiRest
{
    protected $app;
    public function __construct(\think\App $app)
    {
        $this->app = $app;
    }
    public function aliyunCallBack()
    {
        $this->request = $this->app->request;
        $inputs = json_decode($this->request->getInput(), true);
        if(empty($inputs)) {
            $inputs = $_POST;
        }
        $model = new \app\virtual\model\PlayRecord();
        if(!empty($inputs)) {
            foreach ($inputs as $input) {
                $insert = ["uniacid" => $this->_uniacid, "pool_key" => !empty($input["pool_key"]) ? $input["pool_key"] : "", "phone_x" => $input["secret_no"], "phone_a" => $input["phone_no"], "phone_b" => $input["peer_no"], "call_time" => strtotime($input["call_time"]), "start_time" => strtotime($input["start_time"]), "end_time" => strtotime($input["release_time"]), "record_url" => !empty($input["record_url"]) ? $input["record_url"] : "", "call_type" => !empty($input["call_type"]) ? $input["call_type"] : 0, "ring_record_url" => !empty($input["ring_record_url"]) ? $input["ring_record_url"] : "", "out_id" => !empty($input["out_id"]) ? $input["out_id"] : "", "call_id" => $input["call_id"], "sub_id" => $input["sub_id"]];
                $model->dataAdd($insert);
            }
        }
        $res = ["code" => 0, "msg" => "成功"];
        echo json_encode($res);
        exit;
    }
    public function aliyunCallBackMoor()
    {
        $input = $this->_param;
        if(empty($input)) {
            $input = $_GET;
        }
        if(!empty($input["called_show"])) {
            $insert = ["uniacid" => $this->_uniacid, "phone_x" => $input["called_show"], "phone_a" => $input["caller"], "phone_b" => $input["called"], "call_time" => strtotime($input["begin_time"]), "start_time" => strtotime($input["connect_time"]), "end_time" => strtotime($input["release_time"]), "record_url" => !empty($input["record_file_url"]) ? $input["record_file_url"] : "", "ring_record_url" => !empty($input["record_file_url"]) ? $input["record_file_url"] : "", "out_id" => !empty($input["userData"]) ? $input["userData"] : "", "call_id" => $input["recorder_id"], "sub_id" => $input["mappingId"]];
        } else {
            $input["RecordFile"] = $input["FileServer"] . "/" . $input["RecordFile"];
            $order_model = new \app\massage\model\Order();
            $order_id = $order_model->where(["order_code" => $input["WebcallActionID"]])->value("id");
            if(empty($order_id)) {
                $res = ["code" => 0, "msg" => "成功"];
                echo json_encode($res);
                exit;
            }
            $record_model = new \app\virtual\model\Record();
            $phonex = $record_model->where(["order_id" => $order_id])->value("phone_x");
            $insert = ["uniacid" => $this->_uniacid, "phone_x" => $phonex, "phone_a" => $input["CallNo"], "phone_b" => $input["CalledNo"], "call_time" => strtotime($input["Ring"]), "start_time" => strtotime($input["Begin"]), "end_time" => strtotime($input["End"]), "record_url" => $input["RecordFile"], "ring_record_url" => $input["RecordFile"], "out_id" => $order_id, "call_id" => $input["CallID"], "sub_id" => $input["CallSheetID"]];
        }
        $model = new \app\virtual\model\PlayRecord();
        $model->dataAdd($insert);
        $res = ["code" => 0, "msg" => "成功"];
        echo json_encode($res);
        exit;
    }
    public function aliyunCallBackLook()
    {
        $this->request = $this->app->request;
        $input = json_decode($this->request->getInput(), true);
        if(empty($input)) {
            $input = $_POST;
        }
        $insert = ["uniacid" => $this->_uniacid, "phone_x" => $input["displayNumber"], "phone_a" => $input["callerNumber"], "phone_b" => $input["calleeNumber"], "call_time" => strtotime($input["startCallTime"]), "start_time" => strtotime($input["callerAnsweredTime"]), "end_time" => strtotime($input["endTime"]), "record_url" => !empty($input["recUrl"]) ? $input["recUrl"] : "", "ring_record_url" => !empty($input["recUrl"]) ? $input["recUrl"] : "", "out_id" => !empty($input["customerData"]) ? $input["customerData"] : "", "call_id" => $input["callId"], "sub_id" => $input["bindId"]];
        $model = new \app\virtual\model\PlayRecord();
        $model->dataAdd($insert);
        $res = ["code" => 0, "msg" => "成功"];
        echo json_encode($res);
        exit;
    }
}

?>